﻿using System;
using System.Collections.Generic;
using System.Text;

namespace csharpcore7_ch4_multicastDelegate
{
    public delegate void ProgressReporter(int percentComplete);
    public class Util
    {
        public static void HardWork(ProgressReporter p)
        { 
            for(int i =0;i<10;i++)
            {
                p(i * 10);                              //执行委托
                System.Threading.Thread.Sleep(100);     //模拟长时间任务
            }
        }
    }
    class DelegateMulticastDelegateExample3
    {
        static void _Main()
        {
            ProgressReporter p = WriteProgressToConsole;
            p += WriteProgrerssToFile;
            Util.HardWork(p);
        }
        static void WriteProgressToConsole(int percentComplete)
            => Console.WriteLine(percentComplete);
        static void WriteProgrerssToFile(int percentComlete)
        {
            System.IO.File.WriteAllText("progress.txt",percentComlete.ToString());
        }
    }
}
